<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>04vue-文本校验</title>
    <script type="text/javascript" src="static/vue.min.js"></script>
</head>
<body>
<div id="vue">
    <!--$event当前触发的事件-->
    Num: <input type="text" v-on:keydown="validateNum($event)"><br>
    Words:<input type="text" v-on:keydown="validateWords($event)"><br>
</div>
<script>
    new Vue({
        el: "#vue",
        data: {},
        methods: {
            validateNum: function (e) {
                console.log(e);
                // 只能输入0-9的数字 取消shift键的功能
                if (e.keyCode < 48 || e.keyCode > 57 || e.shiftKey == true) {
                    e.preventDefault();
                }
            },
            validateWords: function (e) {
                console.log(e);
                if (e.keyCode < 65 || e.keyCode > 90) {
                    e.preventDefault();
                }
            }

        }

    });
</script>
</body>
</html>